package com.kylin.shared.common;

import lombok.Builder;
import lombok.Value;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 分页查询结果对象
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年05月30日 21:47
 */
@Value
@Builder
public class PageResults {
    long index;
    long limit;
    long total;
    Object results;

    public <T> List<T> castResults(Class<T> clazz) {
        if(!(results instanceof List<?>)) {
            return Collections.emptyList();
        }
        List<T> castedList = new ArrayList<>();
        for (Object o : (List<?>) results) {
            castedList.add(clazz.cast(o));
        }
        return castedList;
    }
}
